//
//  GQHPasswordView.m
//  Xanthium
//
//  Created by GuanQinghao on 02/03/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHPasswordView.h"
#import "GQHHeader.h"

@interface GQHPasswordView () <UITableViewDelegate,UITableViewDataSource>

@end


@implementation GQHPasswordView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self loadLocalData];
        [self loadUserInterface];
    }
    return self;
}

#pragma mark --Data
- (void)loadLocalData {
    
}

#pragma mark --View
- (void)loadUserInterface {
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = kWhiteColor;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.scrollEnabled = NO;
    if (@available(iOS 11.0, *)) {
        
        tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    [self addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.qh_statusBarHeight + self.qh_navigationBarHeight);
        make.left.and.right.and.bottom.mas_equalTo(self);
    }];
}

#pragma mark --Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 50.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (0 == indexPath.row) {
        
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        UILabel *captionLabel = [[UILabel alloc] init];
        captionLabel.font = kBiggerFont;
        captionLabel.text = @"新密码";
        captionLabel.textColor = kDarkGrayColor;
        captionLabel.textAlignment = NSTextAlignmentLeft;
        [cell.contentView addSubview:captionLabel];
        [captionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.and.bottom.mas_equalTo(cell.contentView);
            make.left.mas_equalTo(cell.contentView).with.offset(GQH_MARGIN_SINGLE);
            make.width.mas_equalTo(80);
        }];
        
        UIView *containerView = [[UIView alloc] init];
        containerView.backgroundColor = kAppleGrayColor;
        containerView.layer.cornerRadius = 5.0;
        containerView.layer.masksToBounds = YES;
        [cell.contentView addSubview:containerView];
        [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(cell.contentView).with.offset(5);
            make.bottom.mas_equalTo(cell.contentView).with.inset(5);
            make.left.mas_equalTo(captionLabel.mas_right);
            make.right.mas_equalTo(cell.contentView).with.inset(GQH_MARGIN_SINGLE);
        }];
        
        _qh_passwordTextField = [[UITextField alloc] init];
        _qh_passwordTextField.backgroundColor = kClearColor;
        _qh_passwordTextField.font = kBiggerFont;
        _qh_passwordTextField.textColor = kDarkBlackColor;
        _qh_passwordTextField.placeholder = @"请输入新密码";
        _qh_passwordTextField.secureTextEntry = YES;
        _qh_passwordTextField.textAlignment = NSTextAlignmentLeft;
        [containerView addSubview:_qh_passwordTextField];
        [_qh_passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(containerView).with.offset(5);
            make.bottom.mas_equalTo(containerView).with.inset(5);
            make.left.mas_equalTo(containerView).with.offset(10);
            make.right.mas_equalTo(containerView).with.inset(5);
        }];
        
        return cell;
    } else {
        
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        UILabel *captionLabel = [[UILabel alloc] init];
        captionLabel.font = kBiggerFont;
        captionLabel.text = @"确认密码";
        captionLabel.textColor = kDarkGrayColor;
        captionLabel.textAlignment = NSTextAlignmentLeft;
        [cell addSubview:captionLabel];
        [captionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.and.bottom.mas_equalTo(cell.contentView);
            make.left.mas_equalTo(cell.contentView).with.offset(GQH_MARGIN_SINGLE);
            make.width.mas_equalTo(80);
        }];
        
        UIView *containerView = [[UIView alloc] init];
        containerView.backgroundColor = kAppleGrayColor;
        containerView.layer.cornerRadius = 5.0;
        containerView.layer.masksToBounds = YES;
        [cell.contentView addSubview:containerView];
        [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(cell.contentView).with.offset(5);
            make.bottom.mas_equalTo(cell.contentView).with.inset(5);
            make.left.mas_equalTo(captionLabel.mas_right);
            make.right.mas_equalTo(cell.contentView).with.inset(GQH_MARGIN_SINGLE);
        }];
        
        _qh_againTextField = [[UITextField alloc] init];
        _qh_againTextField.backgroundColor = kClearColor;
        _qh_againTextField.font = kBiggerFont;
        _qh_againTextField.textColor = kDarkBlackColor;
        _qh_againTextField.placeholder = @"请再次输入新密码";
        _qh_againTextField.secureTextEntry = YES;
        _qh_againTextField.textAlignment = NSTextAlignmentLeft;
        [containerView addSubview:_qh_againTextField];
        [_qh_againTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(containerView).with.offset(5);
            make.bottom.mas_equalTo(containerView).with.inset(5);
            make.left.mas_equalTo(containerView).with.offset(10);
            make.right.mas_equalTo(containerView).with.inset(5);
        }];
        
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 10.0f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return [UIView new];
}

@end
